# !/usr/bin/env python
# -*- coding: utf-8 -*-
# ------------------------------
''''''


def main(receive_strs):
    # B人机交互，询问输入字符串
    while True:
        # A询问
        strs = input('请输入字符串（or tab 0+enter to quit!）：')
        if  strs != '0':
            receive_strs.append(strs)
        else:
            break
    # C选出列表第一个字符串元素当模板，并删除列表中的这个元素
    str1 = receive_strs[0]
    receive_strs.pop(0)
    # D定义一个空字串传变量
    tem_str = ""
    flag = 0
    # E对列表进行遍历，拿出每个元素
    for receive_str in receive_strs:
        # 1判断是否tem_str为空，防止遍历第二个元素又相同再加入
        if tem_str == "":
            for str_char1, str_char2 in zip(str1, receive_str):
                if str_char1 == str_char2:
                    tem_str += str_char1
                else:
                    break
        else:
            if len(receive_str) >= len(tem_str):
                for str_char3, str_char4 in zip(tem_str, receive_str):
                    if str_char3 == str_char4:
                        pass
                    else:
                        tem_str = tem_str.replace('{}'.format(str_char3), '')
            elif len(receive_str) < len(tem_str):
                for str_char3, str_char4 in zip(tem_str, receive_str):
                    if str_char3 == str_char4:
                        flag += 1
                tem_str = tem_str[:flag]
    return tem_str
if __name__ == '__main__':
    # A创建一个空列表来接收用户输入的字符串
    receive_strs = []
    result = main(receive_strs)
    # F提示打印
    print('最长前缀是：{}'.format(result))












